﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;

namespace Com.Becom.CommonLibrary.Db.AdoNet
{

    /// <summary>
    /// 基于ADO.NET的数据库管理类。
    /// </summary>
    public class DbManager
    {

        /// <summary>
        /// 创建AbstractDb数据库交互实例。
        /// </summary>
        /// <returns>AbstractDb数据库交互实例</returns>
        public static AbstractDb CreateAbstractDb()
        {
            string DB_TYPE = ConfigurationSettings.AppSettings["DB_TYPE"];
            if (DB_TYPE.ToUpper() == "MYSQL")
            {
                SqlServerDbFactory sqlServerDbFactory = new SqlServerDbFactory();
                return sqlServerDbFactory.CreateDbManager();
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 判断数据集是否为空。null、无表、无记录都算空。
        /// </summary>
        /// <param name="dataSet">待判断的数据集。</param>
        /// <returns>true表示空。</returns>
        public static bool DataSetIsEmpty(DataSet dataSet)
        {
            if (null == dataSet || dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }

}
